import { useMemberStore } from '@/stores'

const user : any = useMemberStore()
const userinfo = user.getUserInfo();

function getChildren(children : any) {
  if (children && Array.isArray(children)) {
    const array : any = [];
    children?.forEach((e, i) => {
      array.push({
        value: e.code,
        label: e.name,
        children: getChildren(e.children),
      });
    });
    return array;
  } else return null;
}
function getNamesValues(tid : any) {
  let dict : any = null;
  for (const key in userinfo?.DICT) {
    if (Object.prototype.hasOwnProperty.call(userinfo?.DICT, key)) {
      if (key == tid) {
        dict = userinfo?.DICT[key];
      }
    }
  }
  const Array : any = [];
  if (dict) {
    dict?.forEach((e, i) => {
      Array.push({
        value: e.code,
        label: e.name,
        // children: getChildren(e.children),
      });
    });
  }
  // console.log('数据字典', Array);
  return Array;
}

function getValueName(tid : any, id : any) {
  const values = getNamesValues(tid);
  const v = values?.find((e : any) => {
    return e.value == id;
  });

  return v?.label || id;
}
function getAddressInfo() {
  return userinfo?.ADDRESS_INFORMATION;
}
export { getNamesValues, getValueName, getAddressInfo };
